package com.sdgs.paas.sdk.core.log;

import com.sdgs.paas.sdk.core.utils.JSONUtils;

/**
 * 日志内容构建器
 *
 * @author wjj
 *
 */
public class PaasLogBuilder {

	private String Content;

	public static final String MetricMethod = "metric-method|";
	public static final String LogContent = "log-content|";
	public static final String DelimitFlag = ",";


//	public String build() {
////		this.TestFlag = MDC.get(PaasHttpHeader.TestFlag);
////		this.ReqClientIP = MDC.get(PaasHttpHeader.ReqClientIP);
////		this.ReqType = MDC.get(PaasHttpHeader.ReqType);
////		this.ReqBizNum = MDC.get(PaasHttpHeader.ReqBizNum);
////		this.ReqTimestamp = MDC.get(PaasHttpHeader.ReqTimestamp);
////		this.ReqDockerIp = MDC.get(PaasHttpHeader.ReqDockerIp);
////		this.ReqType = MDC.get(PaasHttpHeader.ReqType);
////		this.ReqBizNum = MDC.get(PaasHttpHeader.ReqBizNum);
////		this.TraceId = MDC.get(PaasHttpHeader.ReqBizNum);
////		this.PspanId = MDC.get(PaasHttpHeader.PspanId);
////		this.SpanId = MDC.get(PaasHttpHeader.SpanId);
////
////		return this;
//		
//		return new StringBuilder().append(ContentStartFlag).append(Content).toString();
//	}

	/**
	 * 增加SDK日志标志
	 * @param content
	 * 原始日志内容
	 * @return
	 * 标志位+原始日志内容
	 */
	public String addMetricPrefix(String content) {

		return new StringBuilder().append(MetricMethod).append(content).toString();

	}

	public String build(String content) {
		if (content.startsWith(MetricMethod)) {
			this.Content = content;
		} else {
			this.Content = new StringBuilder().append(LogContent).append(content).toString();
		}

		return Content;

	}

	public String toJson() {
		String json = new StringBuilder().append("{").append("\"content\"").append(":\"").append(Content).append("\"}")
				.toString();
		try {
			json = JSONUtils.obj2json(this);
		} catch (Exception e) {
		}

		return json;

	}

//	public String delimit() {
//		String delimit = buildDelimit(TestFlag, ReqClientIP, ReqType, ReqBizNum, ReqTimestamp, ReqDockerIp,
//				RepServUnitName, RepServUnitVersion,
//				// RepTimestamp,
//				ServIp, Port, TraceId, PspanId, SpanId);
//
//		return delimit;
//
//	}
//
//	private String buildDelimit(String... fields) {
//		StringBuilder sb = new StringBuilder();
//		for (String field : fields) {
//			sb.append(field).append(DelimitFlag);
//		}
//
//		return sb.delete(sb.length() - 1, sb.length()).append("$").append(Content).toString();
//
//	}


}